package net.oschina.app.ui.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import net.oschina.app.R;

/**
 * Created by foty on 2017/4/7.
 * ?
 */

public class BlogWebActivity extends AppCompatActivity{
    private Toolbar mToolbar;
    private WebView mWebView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.blog_webview);
        mWebView = (WebView) findViewById(R.id.web_blog);
        mToolbar = (Toolbar) findViewById(R.id.tb_my_blog);
        setSupportActionBar(mToolbar);


        mToolbar.setNavigationIcon(R.drawable.actionbar_back_icon_normal);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //获得url；
        String url = getIntent().getStringExtra("url");
        //展示webview
        mWebView.loadUrl(url);
        mWebView.setWebViewClient(new WebViewClient(){
            //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });

        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptCanOpenWindowsAutomatically(true);// 设置允许js弹出alert
        settings.setJavaScriptEnabled(true);//设置可以加载JS
    }
}
